package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.ABuiding;
import com.ruoyi.lock.service.IABuidingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 建筑架构Controller
 * 
 * @author ruoyi
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/lock/buiding")
public class ABuidingController extends BaseController
{
    @Autowired
    private IABuidingService aBuidingService;

    /**
     * 查询建筑架构列表
     */
    @PreAuthorize("@ss.hasPermi('lock:buiding:list')")
    @GetMapping("/list")
    public AjaxResult list(ABuiding aBuiding)
    {
        List<ABuiding> list = aBuidingService.selectABuidingList(aBuiding);
        return success(list);
    }

    /**
     * 导出建筑架构列表
     */
    @PreAuthorize("@ss.hasPermi('lock:buiding:export')")
    @Log(title = "建筑架构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ABuiding aBuiding)
    {
        List<ABuiding> list = aBuidingService.selectABuidingList(aBuiding);
        ExcelUtil<ABuiding> util = new ExcelUtil<ABuiding>(ABuiding.class);
        util.exportExcel(response, list, "建筑架构数据");
    }

    /**
     * 获取建筑架构详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:buiding:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(aBuidingService.selectABuidingByDeptId(deptId));
    }

    /**
     * 新增建筑架构
     */
    @PreAuthorize("@ss.hasPermi('lock:buiding:add')")
    @Log(title = "建筑架构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ABuiding aBuiding)
    {
        return toAjax(aBuidingService.insertABuiding(aBuiding));
    }

    /**
     * 修改建筑架构
     */
    @PreAuthorize("@ss.hasPermi('lock:buiding:edit')")
    @Log(title = "建筑架构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ABuiding aBuiding)
    {
        return toAjax(aBuidingService.updateABuiding(aBuiding));
    }

    /**
     * 删除建筑架构
     */
    @PreAuthorize("@ss.hasPermi('lock:buiding:remove')")
    @Log(title = "建筑架构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(aBuidingService.deleteABuidingByDeptIds(deptIds));
    }

    /**
     * 获取部门树列表
     */
//    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/deptTree")
    public AjaxResult deptTree(ABuiding dept)
    {
        return success(aBuidingService.selectDeptTreeList(dept));
    }
}
